/*********************************************************************************
 *      Copyright:  (C) 2022 Li Yanting<liyanting2@163.com>
 *                  All rights reserved.
 *
 *       Filename:  cmd.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(05/06/2022)
 *         Author:  Li Yanting <liyanting2@163.com>
 *      ChangeLog:  1, Release initial version on "05/06/2022 10:08:54"
 *                 
 ********************************************************************************/
#ifndef _AT_CMD_H_
#define _AT_CMD_H_

#include "serial.h"
#include "pdu.h"
#include "logger.h"

typedef struct gsm_ctx_s
{
    int  status;
    int  sim_signal;
}gsm_ctx_t;

enum
{
    GSM_STATUS_INIT = 0,                    //SIM card and serial port initial status.
    GSM_STATUS_SERIAL_READY,                //Serial port ready.
    GSM_STATUS_SIM_EXIST,                   //SIM card exist.
    GSM_STATUS_SIM_REG,                     //SIM card already register.
    GSM_STATUS_SIM_SIG,                     //SIM card have signal/
    GSM_STATUS_READY = GSM_STATUS_SIM_SIG,  //SIM card and serial port all ready.
};

/*********************************************************************************
 *      Function name:  send_cmd
 *        Description:  Check whether the specified table has data
 *         @parameter:  attr  
 *         @parameter:  at_cmd  
 *         @parameter:  expect_recv  
 *         @parameter:  recv_buf  
 *         @parameter:  buf_size  
 *         @parameter:  timeout    
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int send_cmd(attr_ctx_t *attr, char * at_cmd, char *expect_recv, char *recv_buf, int buf_size, int timeout);


/*********************************************************************************
 *      Function name:  check_serial_communicate
 *        Description:  Check whether the serial port communicates successfully
 *         @parameter:  attr   
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int check_serial_ready(attr_ctx_t *attr);


/*********************************************************************************
 *      Function name:  check_sim_exist
 *        Description:  Check whether SMS card exists
 *         @parameter:  attr   
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int check_sim_exist(attr_ctx_t *attr);


/*********************************************************************************
 *      Function name:  check_sim_register
 *        Description:  Check whether SMS card is registered
 *         @parameter:  attr   
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int check_sim_register(attr_ctx_t *attr);


/*********************************************************************************
 *      Function name:  check_signal_strength
 *        Description:  Check signal strength
 *         @parameter:  attr   
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int check_signal_strength(attr_ctx_t *attr);


/*********************************************************************************
 *      Function name:  check_sim_allready
 *        Description:  Check whether all are ready
 *         @parameter:  attr   
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
// int check_sim_allready(attr_ctx_t *attr);
int check_sim_allready(attr_ctx_t *attr, gsm_ctx_t *st_gsm);


/*********************************************************************************
 *      Function name:  get_center_number
 *        Description:  get center number
 *         @parameter:  attr   
 *         @parameter:  center_number_buf   
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int get_center_number(attr_ctx_t *attr, char *center_number_buf);


/*********************************************************************************
 *      Function name:  send_text_sms
 *        Description:  send text sms
 *         @parameter:  attr   
 *         @parameter:  phone_number   
 *         @parameter:  sms_buf   
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int send_text_sms( attr_ctx_t *attr, char *phone_number, char *sms_buf);


/*********************************************************************************
 *      Function name:  send_pdu_sms
 *        Description:  send pdu sms
 *         @parameter:  attr   
 *         @parameter:  phone_number   
 *         @parameter:  sms_buf   
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int send_pdu_sms(attr_ctx_t *attr, char *phone_number, char *sms_buf);


/*********************************************************************************
 *      Function name:  delete_all_sms
 *        Description:  delete all sms
 *         @parameter:  attr   
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int delete_all_sms(attr_ctx_t *attr);


/*********************************************************************************
 *      Function name:  get_recv_sms
 *        Description:  Get PDU string
 *         @parameter:  attr   
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int get_recv_sms(char *recv, char *str_sms_buf);


/*********************************************************************************
 *      Function name:  get_specify_sms
 *        Description:  Display specified SMS
 *         @parameter:  attr   
 *         @parameter:  index     
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int get_specify_sms(attr_ctx_t *attr, int index);


/*********************************************************************************
 *      Function name:  display_all_sms
 *        Description:  Display all sms
 *         @parameter:  attr   
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int display_all_sms(attr_ctx_t *attr);


/*********************************************************************************
 *      Function name:  listen_sms
 *        Description:  Check whether the specified table has data
 *         @parameter:  attr  
 *         @parameter:  num  
 *         @parameter:  timeout  
 *         @parameter:  num_buf  
 *         @parameter:  str_num_buf  
 *         @parameter:  time_buf  
 *         @parameter:  utf8_buf  
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int listen_sms(attr_ctx_t *attr, char *num, int timeout, char *num_buf, char *str_num_buf, char *time_buf, char *utf8_buf);


/*********************************************************************************
 *      Function name:  display_spci_num_sms
 *        Description:  Display the information of the specified number
 *         @parameter:  attr   
 *         @parameter:  specify_numb  
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int display_spci_num_sms(attr_ctx_t *attr, char *specify_numb);


/*********************************************************************************
 *      Function name:  display_sms
 *        Description:  Display all information of SMS
 *         @parameter:  str_buf  received SMS
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int display_sms(char *str_buf);


// /*********************************************************************************
//  *      Function name:  dial_up
//  *        Description:  Command dial-up
//  *         @parameter:  attr  
//  *       Return value:  On error, -1 is returned. On success, 0 is returned.
//  ********************************************************************************/
// int dial_up(attr_ctx_t *attr);

#endif